package io.summer.demo.controller;

import cn.hutool.core.collection.ListUtil;
import io.summer.basis.api.ApiResponse;
import io.summer.demo.channel.TestInterface;
import io.summer.basis.api.WrapResponse;
import io.summer.demo.entity.example.Customer;
import io.summer.demo.entity.example.query.QCustomer;
import io.summer.gadget.channel.core.autoconfig.ChannelProxyRegistry;
import io.summer.demo.service.TestService;
import io.summer.gadget.channel.core.anno.RpcService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author Moonlight
 */
@RestController
@WrapResponse
@Slf4j
public class HelloController {
  @Resource
  TestService testService;

  @RpcService
  TestInterface testInterface;

  @GetMapping("/hello")
  public Object hello() throws Exception {
    return "hello summer";
  }

  @GetMapping("/proxy")
  public Object proxy() throws Exception {
    return testInterface.hello(ListUtil.of("hello", "channel"));
  }

  @GetMapping("/cache1")
  public Object cache1() throws Exception {
    return testService.getValue();
  }

  @GetMapping("/cache2")
  public ApiResponse cache2() throws Exception {
    log.error("cache2--");
    return ApiResponse.ok().putData("dd", "1");
//    return testService.getTestVo();
  }

  @GetMapping("/hellox")
  public Object hellox() throws Exception {
    Customer customer = new Customer("Bar");
    customer.save();

    Customer found = new QCustomer()
      .name.istartsWith("ba")
      .findOne();
    return found;
  }
}
